const ckv = require('./index')
const fs = require('fs')
const xmlfile = process.argv[2];
const outAs = process.argv[3];

function load(e) {
    return `
function ${e}(ribbonUI){
    if (typeof (wps.ribbonUI) != "object"){
        wps.ribbonUI = ribbonUI
    }
    return true
}
`
}

try {
    const xmlContent = fs.readFileSync(xmlfile, 'utf-8')
    const callbacks = ckv.callbackKeyAndValue(xmlContent)

    let fns = callbacks.map((e, i) => {
        let fir = e[0];
        let sec = e[1];
        if (fir == "onLoad") {
            return load(sec)
        } else {
            return `
function ${sec}(control){
    const eleId = control.Id
}\n`
        }
    })
    fs.writeFileSync(outAs, fns.join('\n'), { encoding: 'utf-8' })
} catch (e) {
    console.log(e)
}